package de.Torganzier.presentation.GUI;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.ScrollPane;
import java.awt.dnd.DropTarget;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.DefaultListModel;
import javax.swing.DropMode;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.ListModel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import de.Torgenizer.persistence.POJO.Mittarbeiter;


public class MainFrame extends JFrame{
	
	private static final long serialVersionUID = 1L;
	private JTable table;
	private JList employeeList;
	private JPanel toolBox;
	private JButton addButton;
	private JButton removeButton;
	private DefaultListModel employeeListModle;
	private ActionListener actionListner;
	private AddEmployeeDialog addEmployeeDialog;
	
	
	
	public JButton getAddButton() {
		return addButton;
	}
	
	public void setMenu(JMenuBar menu){
		this.setJMenuBar(menu);
	}
	
	public void initTable(){
		String columnNames[] = {" ", "Abteilung1","Abteilung2"};
		String rowData[][] = { {"Montag","Mittarbeiter1","Mittarbeiter 2"} ,{"Montag","Mittarbeiter1","Mittarbeiter 2"},{"Dienstag","Mittarbeiter1","Mittarbeiter 2"}};
		table = new JTable(rowData, columnNames);
		table.getColumnModel().getColumn(0).setWidth(80);
	}
	
	public void initEmployeeList(){
		employeeListModle = new DefaultListModel();
		employeeList = new JList(employeeListModle);
		addButton  = new JButton();
		addButton.setPreferredSize(new Dimension(40, 40));
		ImageIcon addIcon = new ImageIcon("add.gif");
		addButton.setIcon(addIcon);
		addButton.addActionListener(this.actionListner);
		removeButton = new JButton();
		removeButton.setPreferredSize(new Dimension(40, 40));
		removeButton.setIcon(new ImageIcon("remove.png"));
		employeeList.setDragEnabled(true);
		
		
	}
	
	public void initFrame(){

		initTable();
		initEmployeeList();
		addEmployeeDialog = new AddEmployeeDialog(this,this.actionListner);
		addEmployeeDialog.setModal(true);
		this.setLayout(new BoxLayout(getContentPane(), BoxLayout.LINE_AXIS));
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		Box tableBox = Box.createHorizontalBox();
		Box mainBox = Box.createVerticalBox();
		Box employeeListBox = Box.createVerticalBox();
		employeeListBox.add(new JScrollPane(employeeList));
		Box employeeListButtonBox = Box.createHorizontalBox();
		
		employeeListBox.add(employeeListButtonBox);
		employeeListButtonBox.add(addButton);
		employeeListButtonBox.add(removeButton);
		employeeListButtonBox.add(Box.createHorizontalGlue());
		tableBox.add(new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(table), employeeListBox));
		mainBox.add(tableBox);
		this.add(mainBox);
	}
	
	public Object getAddEmployeeOKClicked(){
		
		return addEmployeeDialog.getOKButton();
	}
	
	public Object getAddEmployeeAbortClicked(){
		return addEmployeeDialog.getAbbortButton();
	}
	
	public String getAddEmplyeeFirstNameEntry(){
		return addEmployeeDialog.getFirstName();
	}
	
	public String getAddEmployessLastNameEntry(){
		return addEmployeeDialog.getLastName();
	}
	
	public void closeAddEmployeeDialog(){
		addEmployeeDialog.setVisible(false);
	}
	
	public void shwoAddEmployeeDialog(){
		this.addEmployeeDialog.setVisible(true);
	}
	
	public void setEmployeeList(ArrayList<Mittarbeiter> content){
		employeeListModle.clear();
		for (int i=0;i<content.size();i++){
			this.employeeListModle.addElement(content.get(i).toString());
		}
	}
	
	public MainFrame(ActionListener actionListner){
		this.actionListner = actionListner;
		initFrame();
	}

	
}
